<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="es,">










<meta name="description" content="基本概念对比MySQL来说，文档document&amp;lt;-&amp;gt;行记录 row record，类型type&amp;lt;-&amp;gt;表 table，索引index&amp;lt;-&amp;gt; 数据库 逻辑设计文档（Document）文档是es中数据的最小单位，有几个重要的属性。  一个文档同时包含字段名，和字段值 可以是层次型的，互相包含 文档并不依赖于事先定义的结构，可以随意新增和删除字段  类型（Mappin">
<meta name="keywords" content="es">
<meta property="og:type" content="article">
<meta property="og:title" content="了解一下">
<meta property="og:url" content="https://arrycoder.gitee.io/elasticsearch/官方文档命令/index.html">
<meta property="og:site_name" content="arry&#39;s blog">
<meta property="og:description" content="基本概念对比MySQL来说，文档document&amp;lt;-&amp;gt;行记录 row record，类型type&amp;lt;-&amp;gt;表 table，索引index&amp;lt;-&amp;gt; 数据库 逻辑设计文档（Document）文档是es中数据的最小单位，有几个重要的属性。  一个文档同时包含字段名，和字段值 可以是层次型的，互相包含 文档并不依赖于事先定义的结构，可以随意新增和删除字段  类型（Mappin">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2020-08-25T08:48:03.111Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="了解一下">
<meta name="twitter:description" content="基本概念对比MySQL来说，文档document&amp;lt;-&amp;gt;行记录 row record，类型type&amp;lt;-&amp;gt;表 table，索引index&amp;lt;-&amp;gt; 数据库 逻辑设计文档（Document）文档是es中数据的最小单位，有几个重要的属性。  一个文档同时包含字段名，和字段值 可以是层次型的，互相包含 文档并不依赖于事先定义的结构，可以随意新增和删除字段  类型（Mappin">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://arrycoder.gitee.io/elasticsearch/官方文档命令/">





  <title>了解一下 | arry's blog</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?97f9adfda8d04eb91dd054a98264d191";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">arry's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://arrycoder.gitee.io/blog/elasticsearch/官方文档命令/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="arry">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/blog/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="arry's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">了解一下</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2020-07-30T11:51:20+08:00">
                2020-07-30
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/es/" itemprop="url" rel="index">
                    <span itemprop="name">es</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="基本概念"><a href="#基本概念" class="headerlink" title="基本概念"></a>基本概念</h1><p>对比MySQL来说，文档document&lt;-&gt;行记录 row record，类型type&lt;-&gt;表 table，索引index&lt;-&gt; 数据库</p>
<h2 id="逻辑设计"><a href="#逻辑设计" class="headerlink" title="逻辑设计"></a>逻辑设计</h2><h3 id="文档（Document）"><a href="#文档（Document）" class="headerlink" title="文档（Document）"></a>文档（Document）</h3><p>文档是es中数据的最小单位，有几个重要的属性。</p>
<ol>
<li>一个文档同时包含字段名，和字段值</li>
<li>可以是层次型的，互相包含</li>
<li>文档并不依赖于事先定义的结构，可以随意新增和删除字段</li>
</ol>
<h3 id="类型（Mapping-types）"><a href="#类型（Mapping-types）" class="headerlink" title="类型（Mapping types）"></a>类型（Mapping types）</h3><p>类似于数据库中的表，用来保存文档的结构。虽然文档是无模式的，但是我们最好将一种业务类型的数据放到同一个类型中。如果一个文档包含了新的字段，es也会将猜测他的类型，比如7-&gt;长整型,然后将这个文档存放起来。但是 猜测有时候也会出错，如果先映射了a字段为长整型，这时候再新增字符串类型的，就会出错。</p>
<h3 id="索引-（Index）"><a href="#索引-（Index）" class="headerlink" title="索引 （Index）"></a>索引 （Index）</h3><p>索引是映射类型的容器，类似数据库。索引除了存储各个独立的类型，还存放着索引的设置，比如刷新时间。</p>
<h2 id="物理设计"><a href="#物理设计" class="headerlink" title="物理设计"></a>物理设计</h2><h3 id="节点"><a href="#节点" class="headerlink" title="节点"></a>节点</h3><p>一个es实例就是一个节点，多个节点可以组成一个集群。我们也可以在一个服务器上启动多个实例。多个节点组成的集群可以保证es服务的稳定性，同时每个主分片都有副分片，能一定程度上提供容错性。</p>
<h3 id="分片"><a href="#分片" class="headerlink" title="分片"></a>分片</h3><p>一份分片是Lucene的一个索引，一个倒排索引。默认包含了文档的原始内容，以及词条字典和词频。词条字典和词频用来帮助es快速定位文档。</p>
<p>分片可以是主分片和副分片，副本分片是主分片的完整副本。</p>
<hr>
<p>新建索引：curl -X PUT “0.0.0.0:9300/customer?pretty”<br>新增文档：curl -X PUT “0.0.0.0:9300/customer/doc/1?pretty” -H ‘Content-Type: application/json’ -d’<br>{<br>  “name”: “John Doe”<br>}<br>‘<br>查询文档：curl -X GET “0.0.0.0:9300/customer/doc/1?pretty”<br>删除索引：curl -X DELETE “0.0.0.0:9300/customer?pretty”</p>
<p>新增文档：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">curl -X PUT <span class="string">"0.0.0.0:9300/customer/doc/12/?pretty&amp;pretty"</span> -H <span class="string">'Content-Type: application/json'</span> -d<span class="string">'</span></span><br><span class="line"><span class="string">&#123;</span></span><br><span class="line"><span class="string">  "doc": &#123; "name": "chen", "order":3 &#125;</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string">'</span></span><br></pre></td></tr></table></figure>

<p>更新文档：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">curl -X POST <span class="string">"0.0.0.0:9300/customer/doc/1/_update?pretty&amp;pretty"</span> -H <span class="string">'Content-Type: application/json'</span> -d<span class="string">'</span></span><br><span class="line"><span class="string">&#123;</span></span><br><span class="line"><span class="string">  "doc": &#123; "name": "Number", "order":1 &#125;</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string">'</span></span><br></pre></td></tr></table></figure>

<p>导入json：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">curl -H <span class="string">"Content-Type: application/json"</span> -XPOST <span class="string">'0.0.0.0:9300/bank/account/_bulk?pretty&amp;refresh'</span> --data-binary <span class="string">"@querying.json"</span></span><br><span class="line">curl <span class="string">'0.0.0.0:9300/_cat/indices?v'</span></span><br></pre></td></tr></table></figure>

<h2 id="queryAPI"><a href="#queryAPI" class="headerlink" title="queryAPI"></a>queryAPI</h2><p>curl -X GET “0.0.0.0:9300/bank/_search?q=*&amp;sort=account_number:asc&amp;pretty&amp;pretty”</p>
<h3 id="Query-DSL"><a href="#Query-DSL" class="headerlink" title="Query DSL"></a>Query DSL</h3><p>DSL是一种json形式的query body</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">curl -X GET <span class="string">"0.0.0.0:9300/bank/_search?pretty"</span> -H <span class="string">'Content-Type: application/json'</span> -d<span class="string">'</span></span><br><span class="line"><span class="string">&#123;</span></span><br><span class="line"><span class="string">	"_source":["firstname", "age"],</span></span><br><span class="line"><span class="string">  "query": &#123;</span></span><br><span class="line"><span class="string">    "match_all":&#123;&#125;</span></span><br><span class="line"><span class="string">  &#125;</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string">'</span></span><br></pre></td></tr></table></figure>

<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">curl -X GET <span class="string">"0.0.0.0:9300/_mget?pretty"</span> -H <span class="string">'Content-Type: application/json'</span> -d<span class="string">'</span></span><br><span class="line"><span class="string">&#123;</span></span><br><span class="line"><span class="string">  "docs": [</span></span><br><span class="line"><span class="string">    &#123;</span></span><br><span class="line"><span class="string">      "_index": "customer",</span></span><br><span class="line"><span class="string">      "_id": "1"</span></span><br><span class="line"><span class="string">    &#125;,</span></span><br><span class="line"><span class="string">    &#123;</span></span><br><span class="line"><span class="string">      "_index": "bank",</span></span><br><span class="line"><span class="string">      "_id": "2"</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  ]</span></span><br><span class="line"><span class="string">&#125;</span></span><br></pre></td></tr></table></figure>



<hr>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/es/" rel="tag"># es</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/zk/zab/" rel="next" title="zab协议">
                <i class="fa fa-chevron-left"></i> zab协议
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/elasticsearch/基本概念/" rel="prev" title="基本概念">
                基本概念 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/blog/uploads/avatar.jpg" alt="arry">
            
              <p class="site-author-name" itemprop="name">arry</p>
              <p class="site-description motion-element" itemprop="description">Java源码/设计模式/个人记录</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">42</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">11</span>
                  <span class="site-state-item-name">categories</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">18</span>
                  <span class="site-state-item-name">tags</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#基本概念"><span class="nav-number">1.</span> <span class="nav-text">基本概念</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#逻辑设计"><span class="nav-number">1.1.</span> <span class="nav-text">逻辑设计</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#文档（Document）"><span class="nav-number">1.1.1.</span> <span class="nav-text">文档（Document）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#类型（Mapping-types）"><span class="nav-number">1.1.2.</span> <span class="nav-text">类型（Mapping types）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#索引-（Index）"><span class="nav-number">1.1.3.</span> <span class="nav-text">索引 （Index）</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#物理设计"><span class="nav-number">1.2.</span> <span class="nav-text">物理设计</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#节点"><span class="nav-number">1.2.1.</span> <span class="nav-text">节点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#分片"><span class="nav-number">1.2.2.</span> <span class="nav-text">分片</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#queryAPI"><span class="nav-number">1.3.</span> <span class="nav-text">queryAPI</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Query-DSL"><span class="nav-number">1.3.1.</span> <span class="nav-text">Query DSL</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">arry</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
